def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def find_largest_prime(number):
    if len(str(number)) != 4:
        return 0

    digits = [int(d) for d in str(number)]
    primes = []

    for i in range(4):
        for j in range(i, 4):
            if i != j:
                num = int(str(digits[i]) + str(digits[j]))
                if is_prime(num):
                    primes.append(num)

    if not primes:
        return 0

    return max(primes)

number = int(input())
result = find_largest_prime(number)
print(result)